home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / r1_hello.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  4KB  |  136 lines

  1. {$X+,V-,B-}
  2. program RecHello1;
  3.  
  4. { Simple IPX demonstration program, that uses one receive ESR.
  5.  
  6.   Run this program on 1 workstation, run S_HELLO or S1_HELLO on another.
  7.   S_HELLO will send "hello world" messages,
  8.   this workstation will receive them.  }
  9.  
  10. uses crt,nwMisc,nwIPX;
  11.  
  12. CONST IOSocket=$5678;
  13.  
  14. Var ReceiveEcb    :Tecb;
  15.     IpxHdr        :TipxHeader;
  16.     socket        :word;
  17.     buf           :array[1..546] of byte;
  18.     t             :byte;
  19.     ReceivedBufLen:word;
  20.     PacketReceived:boolean;
  21.  
  22.     NewStack:array[1..1024] of word;  { !! used by ESR }
  23.     StackBottom:word;                 { !! used by ESR }
  24.  
  25.  
  26. {$F+}
  27. Procedure ListenESRhandler;
  28. begin
  29. PacketReceived:=true;
  30. end;
  31. {$F-}
  32.  
  33. {$F+}
  34. Procedure ListenESR; assembler;
  35. asm { ES:SI are the only valid registers when entering this procedure ! }
  36.     mov dx, seg stackbottom
  37.     mov ds, dx
  38.  
  39.     mov dx,ss  { setup of a new local stack }
  40.     mov bx,sp  { ss:sp copied to dx:bx}
  41.     mov ax,ds
  42.     mov ss,ax
  43.     mov sp,offset stackbottom
  44.     push dx
  45.     push bx
  46.  
  47.     CALL ListenEsrHandler
  48.  
  49.     pop bx
  50.     pop dx
  51.     mov sp,bx { restore stack }
  52.     mov ss,dx
  53. end;
  54. {$F-}
  55.  
  56.  
  57. begin
  58. IF NOT IpxInitialize
  59.  then begin
  60.       writeln('Ipx needs to be installed.');
  61.       halt(1);
  62.       end;
  63. socket:=IOSocket;
  64. IF NOT IPXopenSocket(Socket,SHORT_LIVED_SOCKET)
  65.  then begin
  66.       writeln('IPXopenSocket returned error# ',nwIPX.result);
  67.       halt(1);
  68.       end;
  69.  
  70. Repeat
  71.    PacketReceived:=False;
  72.    { Empty receive buffer (ReceiveEcb.fragment[2].address^) }
  73.    FillChar(buf,546,#0);
  74.  
  75.    { Setup ECB and IPX header }
  76.    IPXsetupListenECB(Addr(ListenESR),IOsocket,@buf,546,
  77.                      IpxHdr,ReceiveEcb);
  78.  
  79.    IPXListenForPacket(ReceiveECB);
  80.  
  81.   REPEAT
  82.  
  83.    delay(1000);
  84.    Writeln('Packet received: ',PacketReceived);
  85.  
  86.    IF PacketReceived { ESR has signalled that a packet has been received }
  87.     then begin
  88.          Case ReceiveECB.CompletionCode OF
  89.           $00:begin { Dump received bytes.. }
  90.               Write('Data received  : ');
  91.               ReceivedBufLen:=swap(IpxHdr.length)-SizeOf(TipxHeader);
  92.               for t:=1 to ReceivedBufLen
  93.                do write(chr(buf[t]));
  94.               writeln;
  95.               end;
  96.           $FC:Writeln('The listen request has been canceled.');
  97.               { impossible, as the cancelation has to be done by this program, and it doesn't }
  98.           $FD:Writeln('Packet overflow error.');
  99.               { 0 fragments, or receiving buffer too small. }
  100.           $FF:Writeln('The socket is closed.');
  101.               { Impossible. The socket is definitely open. See above. }
  102.          end;
  103.  
  104.          { Now we're going to squeeze all information out of the IpxHdr }
  105.          writeln('*IPX header info*');
  106.          writeln('-total length  : ',swap(IpxHdr.length):0);
  107.          writeln('-data length   : ',swap(IpxHdr.Length)-SizeOf(TipxHeader));
  108.          writeln('-number of hops: ',(IpxHdr.TransportControl AND $0F):0);
  109.          write('-sending adress: [');
  110.          for t:=1 to 4
  111.           do write(HexStr(IpxHdr.source.net[t],2));
  112.          write('|');
  113.          for t:=1 to 6
  114.           do write(HexStr(IpxHdr.source.node[t],2));
  115.          write('|');
  116.          writeln(HexStr(swap(IpxHdr.source.socket),4),']');
  117.          write('-destined for  : [');
  118.          for t:=1 to 4
  119.           do write(HexStr(IpxHdr.destination.net[t],2));
  120.          write('|');
  121.          for t:=1 to 6
  122.           do write(HexStr(IpxHdr.destination.node[t],2));
  123.          write('|');
  124.          writeln(HexStr(swap(IpxHdr.destination.socket),4),']');
  125.  
  126.          writeln;
  127.          end;
  128.  
  129.   UNTIL (KeyPressed or PacketReceived);
  130.  
  131. UNTIL keypressed;
  132.  
  133. IF NOT IPXcloseSocket(IOsocket)
  134.  then writeln('IPXcloseSocket returned error# ',nwIPX.result);
  135.  
  136. end.